<template>
  <div>
    <FilterTable
      ref="table"
      height="400px"
      :isSelectColumn="true"
      :columns="columns"
      :dataSource="dataList"
      :isPagination="false"
      :selectionType="'single'"
      columnsRef="xmzLinkTable"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="onRowSelectChange"
    >
    </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="checkDialog">确 认</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import * as validate from '@/utils/validate.js';
import { getOwnerLinkerInfoAll } from '@/api/customerRepair/customerInfo/ownerVehicleManagement';
import { getUser } from '@/assets/js/auth';
import moment from 'moment';
import { isFormEmpty, confirmAction } from '../../../../../utils';
export default {
  name: 'xmzLinkModel',
  mixins: [dictionary],
  props: ['ownerNo'],
  data() {
    this.selectedRow = null;
    return {
      dataList: [],
      columns: this.createTableColumns()
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
    this.initHandle();
  },
  methods: {
    async initHandle() {
      if (this.ownerNo) {
        this.BaseTable.START_LOADING();
        let res = await getOwnerLinkerInfoAll({ ownerNo: this.ownerNo });
        if (res.resultCode === 200) {
          this.dataList = res.data || [];
        }
        this.BaseTable.STOP_LOADING();
      }
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '联系人姓名',
          dataIndex: 'contactorName',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '主联系人',
          dataIndex: 'mainLink',
          sorter: true,
          filter: true,
          editable: true,
          defaultEditable: true,
          disabled: true,
          filterItems: this.createDictList('1004'),
          filterType: 'radio',
          editType: 'checkbox',
          editItems: [
            { text: '', trueValue: 10041001 },
            { text: '', falseValue: 10041002 }
          ]
        },
        {
          title: '联系人移动电话',
          dataIndex: 'contactorMobile',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '联系人固定电话',
          dataIndex: 'contactorPhone',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    closeDialog(param) {
      this.$emit('close', false, param);
    },
    onRowSelectChange(rows) {
      if (!rows.length) {
        this.selectedRow = null;
      } else {
        this.selectedRow = rows[0];
      }
    },
    async checkDialog() {
      if (isFormEmpty(this.selectedRow)) {
        try {
          await confirmAction('请至少选择一条数据，再进行操作');
          return;
        } catch (err) {}
      } else {
        this.$emit('setLinkInfo', this.selectedRow);
        this.closeDialog('close');
      }
    }
  }
};
</script>

<style lang="less" scoped>
.wrapper {
  height: calc(100vh - 135px);
}
</style>
